package cn.edu.baiyunu.myapplication.data.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import cn.edu.baiyunu.myapplication.data.model.SavingsGoal
import kotlinx.coroutines.flow.Flow

/**
 * 储蓄目标数据访问对象接口
 */
@Dao
interface SavingsGoalDao {
    /**
     * 获取所有储蓄目标
     */
    @Query("SELECT * FROM savings_goals ORDER BY name")
    fun getAllSavingsGoals(): Flow<List<SavingsGoal>>
    
    /**
     * 根据ID获取储蓄目标
     */
    @Query("SELECT * FROM savings_goals WHERE id = :id")
    fun getSavingsGoalById(id: String): Flow<SavingsGoal?>
    
    /**
     * 插入储蓄目标
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertSavingsGoal(savingsGoal: SavingsGoal)
    
    /**
     * 更新储蓄目标
     */
    @Update
    suspend fun updateSavingsGoal(savingsGoal: SavingsGoal)
    
    /**
     * 删除储蓄目标
     */
    @Delete
    suspend fun deleteSavingsGoal(savingsGoal: SavingsGoal)
    
    /**
     * 根据ID删除储蓄目标
     */
    @Query("DELETE FROM savings_goals WHERE id = :id")
    suspend fun deleteSavingsGoalById(id: String)
} 